<?php
/**
 * @version		0.2.0 joomla zmluvy $
 * @package		com_zjmluvy
 * @copyright	Copyright © 2011 - All rights reserved.
 * @license		GNU/GPL
 * @author    AdrianKo		
 * @website   http://code.google.com/p/joomla-zmluvy
 *
 *
 *1.3.2012
 */

// no direct access
defined('_JEXEC') or die('Restricted access');
?>

<script language="javascript" type="text/javascript">
function tableOrdering( order, dir, task )
{
        var form = document.adminForm;
        form.filter_order.value = order;
        form.filter_order_Dir.value = dir;
        document.adminForm.submit( task );
}
</script> 

<?php if ($this->params->get( 'show_page_title', 1 ) && $this->params->get('page_title') != '' ) : ?>
	<div class="componentheading<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
		<?php echo $this->params->get( 'page_title' ).' <span class="stav">('.JText::_('STAV_KU_DNU').' '.StrFTime("%d.%m.%Y", Time()).')</span>'; ?>
  </div>
<?php endif; ?>

<?php echo "<!-- jZmluvy ver.".$this->nastavenie->ver." START -->"; ?>

<form action="<?php echo JRoute::_( 'index.php' );?>" method="post" name="adminForm" id="adminForm" class="form-validate">

<?php // vyvolanie filtra ?>
<?php echo $this->params->get( 'filter') ? '<div id="filter">'.$this->loadTemplate('filter').'</div>':''; ?>
 
<table id="jzmluvy">
 <thead>
  <?php $f=7; if(!$this->params->get( 'detail')): // ak je DETAIL vypnuty tak su zobrazene vsetky povinne udaje?>
  <tr class="heading">
    <?php if($this->params->get( 'datZverejnania')): ?>
    <th>
      <?php echo JHTML::_( 'grid.sort', JText::_('DAT_ZVER'), 'datZver', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>
    <th>
      <?php echo JHTML::_( 'grid.sort', JText::_('DAT_VYHOTOVENIA'), 'datUhrady', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>
    <?php if($this->params->get( 'cisloObj')): ?>
    <th>
      <?php echo JHTML::_( 'grid.sort', JText::_('DET_CISLO_OBJEDNAVKY'), 'faktura', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>
    <th>
      <?php echo JHTML::_( 'grid.sort', JText::_('POPIS_PLNENIA_OBJ'), 'title', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>      
    <th>
      <?php echo JHTML::_( 'grid.sort', JText::_('SUMA'), 'suma', $this->lists['order_Dir'], $this->lists['order']); ?> 
      <?php echo $this->nastavenie->dph ? '&nbsp;'.JText::_('S_DPH') : '&nbsp;'.JText::_('BEZ_DPH'); ?>      
    </th>
    <?php if($this->params->get( 'identZml')): ?>
    <th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('IDENT_ZML'), 'typ_zml', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>
    <th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('PODPIS_OBJ'), 'kontakt', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>
    <th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('DODAVATEL'), 'dodavatel', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>
    <th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('ICO'), 'ico', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>
    <th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('ADRESA'), 'mesto', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>    
    <?php if($this->params->get( 'dokumenty')): ?>
    <th>
      <?php echo   JText::_('DOKUMENTY'); ?>
    </th><?php $f++; endif; ;?>
  </tr>
  
  <?php else : $f=4; // zapnuty  DETAIL ?>
  <tr class="heading">
    <?php if($this->params->get( 'datZverejnania')): ?>
    <th>
      <?php echo JHTML::_( 'grid.sort', JText::_('DAT_ZVER'), 'datZver', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>
    <th>
      <?php echo JHTML::_( 'grid.sort', JText::_('DAT_VYHOTOVENIA'), 'datUhrady', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>
    <?php if($this->params->get( 'cisloObj')): ?>
    <th>
      <?php echo JHTML::_( 'grid.sort', JText::_('DET_CISLO_OBJEDNAVKY'), 'faktura', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>
    <th>
      <?php echo JHTML::_( 'grid.sort', JText::_('POPIS_PLNENIA_OBJ'), 'title', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>
    <th>
      <?php echo JHTML::_( 'grid.sort', JText::_('SUMA'), 'suma', $this->lists['order_Dir'], $this->lists['order']); ?> 
      <?php echo $this->nastavenie->dph ? '&nbsp;'.JText::_('S_DPH') : '&nbsp;'.JText::_('BEZ_DPH'); ?>
    </th>      
    <?php if($this->params->get( 'identZml')): ?>
    <th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('IDENT_ZML'), 'typ_zml', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>      
    <?php if($this->params->get( 'podpis') != 0): ?>
    <th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('PODPIS_OBJ'), 'kontakt', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>     
    <th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('DODAVATEL'), 'dodavatel', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th>
    <?php if($this->params->get( 'ico')): ?>
    <th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('ICO'), 'ico', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>
    <?php if($this->params->get( 'adresa')): ?>
    <th>
      <?php echo  JHTML::_( 'grid.sort', JText::_('ADRESA'), 'mesto', $this->lists['order_Dir'], $this->lists['order']); ?>
    </th><?php $f++; endif; ?>    
    <?php if($this->params->get( 'dokumenty')): ?>
    <th>
      <?php echo   JText::_('DOKUMENTY'); ?>
    </th><?php $f++; endif; ?>
  </tr>
  <?php endif; ?>  
 </thead> 

  <tfoot>
    <tr>
      <td colspan="<?php echo $f; ?>">
        <div class="foot">
          <span class="left">
          <?php echo $this->pagination->getPagesLinks(); ?>&nbsp;
          </span>
          <span class="right">
            <?php echo $this->pagination->getPagesCounter(); ?>
            <?php echo $this->pagination->getLimitBox(); ?>
          </span>
        </div>
      </td>
    </tr>
  </tfoot>
  
  <tbody>
  <?php $k = 0; $stat="";
  foreach ($this->items AS $item) :
  $k++; $e=$k%2;
  $adresa = $item->ulica.",".$item->psc."  ".$item->mesto; 
    if($this->params->get( 'zobr_stat')) { $stat = ", ".$item->stat; }
  $link  = 'index.php?option=com_jzmluvy&view=objednavky&task=download&id='.$item->id;
  $link2 = 'index.php?option=com_jzmluvy&view=objednavky&task=download2&id='.$item->id;
  $link_detail = 'index.php?option=com_jzmluvy&view=objednavky&task=detail&id='.$item->id;

  $link_dod = '#';
  $link_zml = 'index.php?option=com_jzmluvy&view=zmluvy&layout=detail&id='.$item->typ;
  $link_podpis = 'index.php?option=com_contact&view=contact&id='.$item->created_by_alias;

  // ak nie je vyplneny datum zverejnenia tak NIC
  if($item->datZver == "0000-00-00") { $item->datZver = ''; }
  ?>
           
  <?php if(!$this->params->get( 'detail')): // ak je DETAIL vypnuty tak su zobrazene vsetky povinne udaje?>
   <tr class="vypis<?php echo $e; ?>">    
    <?php if($this->params->get( 'datZverejnania')): ?>
    <td class="center">
      <?php echo jzmluvyHelper::fdatum($item->datZver) ?>
    </td><?php endif; ?>
    <td class="center">
      <?php echo jzmluvyHelper::fdatum($item->datUhrady) ?>
    </td>
    <?php if($this->params->get( 'cisloObj')): ?>
    <td>
      <?php echo $item->faktura ?>
    </td><?php endif; ?>
    <td>
      <?php echo $item->title ?>
    </td>
    <td class="right">
      <?php echo jzmluvyHelper::fsuma($item->suma,$item->mena) ?>
    </td>

    <?php //*** identifikacia zmluvy - linkovane ?>
    <?php if(!$item->typ_zml) : $item->typ_zml = $item->typ_zml2; endif; ?>
    <?php if($this->params->get( 'identZml') == 2): ?>
    <td>
      <a href="<?php echo $link_zml; ?>">
        <?php echo (empty($item->typ_zml)) ? $item->zml_text : $item->typ_zml; ?>
      </a>
    <?php if($item->jedcislo && $item->intCislo && $this->nastavenie->crz) : ?>
      <a href="http://<?php echo $item->intCislo; ?>" target="_cr" title="">
        <?php echo $item->jedcislo; ?>
      </a>
      <img src="administrator/components/com_jzmluvy/assets/ext_link.png" height="10" width="10" title="Externý odkaz" alt="Ikona" />
        <?php elseif($this->nastavenie->crz) : ?>
        <?php echo $item->jedcislo; ?>
        <?php else : ?>
    <?php endif; ?></td><?PHP endif; ?>
                              
    <?php //*** identifikacia zmluvy - bez linku ?>
    <?php if($this->params->get( 'identZml') == 1): ?>
    <td>
      <?php if(($item->typ_zml) == '') { echo $item->zml_text; } else { echo $item->typ_zml; } ?>
      <?php if($item->jedcislo && $this->nastavenie->crz) : ?>
      <?php echo $item->jedcislo; ?>
      <?php endif; ?>
    </td>
    <?php endif; ?>
    
    <?php if(!$this->nastavenie->kontakty): ?>
    <td>
      <div>
        <?php echo $item->vlastni1 ?>
      </div>
      <div>
        <?php echo $item->vlastni2 ?>
      </div>
    </td>
  	<?php else: ?>
  	<td>
    <div>
      <?php if($this->params->get( 'podpis') == 2): ?>
      <a href="<?php echo $link_podpis ?>">
        <?php echo $item->kontakt ?>
      </a>
      <?php else : ?>
      <?php echo $item->kontakt ?>
      <?php endif; ?>
    </div>
    <div>
      <?php echo $item->pozicia ?>
    </div>
	  </td><?php endif; ?>
    <td>
    <?php if($this->params->get( 'dodavatel')): ?>
      <a href="<?php echo $link_dod ?>">
        <?php echo $item->fadod ?>
      </a>
      <?php else : ?>
      <?php echo $item->fadod ?>
      <?php endif; ?>
    </td>
    <td>
      <?php echo $item->ico ?>
    </td>
    <td>
      <?php echo $adresa.$stat ?>
    </td>
    <?php if($this->params->get( 'dokumenty')): ?>
    <td class="center">
      <?php if(!empty($item->file)) { ?>
      <?php echo  jzmluvyHelper::subor_scan($item->id,$item->file,$item->filename,$item->extension,$link,$item->hits,0); }?> 
      <?php if(!empty($item->file2)) { ?>
      <?php echo  jzmluvyHelper::subor_text($item->id,$item->file2,$item->filename2,$item->extension2,$link2,$item->hits2,0); ?>
      <?php } ?>
    </td> 
  <?php endif; ?>
  </tr>

  <?php else : // zapnuty detail ?>
  <tr class="vypis<?php echo $e; ?>">  
  <?php if($this->params->get( 'datZverejnania')): ?>
    <td class="center">
      <?php echo jzmluvyHelper::fdatum($item->datZver) ?>
    </td><?php endif; ?>
    <td class="center">
      <?php echo jzmluvyHelper::fdatum($item->datUhrady) ?>
    </td>
    <?php if($this->params->get( 'cisloObj')): ?>
    <td>
      <?php echo $item->faktura ?>
    </td><?php endif; ?>
    <td>
      <a href="<?php echo $link_detail ?>">
        <?php echo $item->title ?>
          <img src="components/com_jzmluvy/assets/images/detail.gif" height="14" width="14" title="Detail" alt="Detail" />
      </a>
    </td>
    <td class="right">
      <?php echo jzmluvyHelper::fsuma($item->suma,$item->mena) ?>
    </td>

    <?php //*** identifikacia zmluvy - linkovane ?>
    <?php if(!$item->typ_zml) : $item->typ_zml = $item->typ_zml2; endif; ?>
    <?php if($this->params->get( 'identZml') == 2): ?>
    <td>
      <a href="<?php echo $link_zml; ?>">
        <?php echo (empty($item->typ_zml)) ? $item->zml_text : $item->typ_zml; ?>
      </a>
    <?php if($item->jedcislo && $item->intCislo && $this->nastavenie->crz) : ?>
      <a href="http://<?php echo $item->intCislo; ?>" target="_cr" title="">
        <?php echo $item->jedcislo; ?>
      </a>
      <img src="administrator/components/com_jzmluvy/assets/ext_link.png" height="10" width="10" title="Externý odkaz" alt="Ikona" />
        <?php elseif($this->nastavenie->crz) : ?>
        <?php echo $item->jedcislo; ?>
        <?php else : ?>
    <?php endif; ?></td><?PHP endif; ?>
                              
    <?php //*** identifikacia zmluvy - bez linku ?>
    <?php if($this->params->get( 'identZml') == 1): ?>
    <td>
      <?php if(($item->typ_zml) == '') { echo $item->zml_text; } else { echo $item->typ_zml; } ?>
      <?php if($item->jedcislo && $this->nastavenie->crz) : ?>
      <?php echo $item->jedcislo; ?>
      <?php endif; ?>
    </td>
    <?php endif; ?>
    
    <?php if($this->params->get( 'podpis')) : ?>
    <?php if(!$this->nastavenie->kontakty): ?>
    <td>
      <div>
        <?php echo $item->vlastni1 ?>
      </div>
      <div>
        <?php echo $item->vlastni2 ?>
      </div>
    </td>
  	<?php else: ?>
  	<td>
      <div>
        <?php if($this->params->get( 'podpis') == 2): ?>
        <a href="<?php echo $link_podpis ?>">
         <?php echo $item->kontakt ?>
        </a>
        <?php else : ?>
        <?php echo $item->kontakt ?><?php endif; ?>
      </div>
      <div>
        <?php echo $item->pozicia ?>
      </div>
	  </td><?php endif; endif; ?>
    <td>
    <?php if($this->params->get( 'dodavatel')): ?>
      <a href="<?php echo $link_dod ?>">
        <?php echo $item->fadod ?>
      </a>
      <?php else : ?>
      <?php echo $item->fadod ?>
      <?php endif; ?>
    </td>
    <?php if($this->params->get( 'ico')): ?>
    <td>
      <?php echo $item->ico ?>
    </td><?php endif; ?>
    <?php if($this->params->get('adresa')): ?>
    <td>
      <?php echo $adresa.$stat ?>
    </td><?php endif; ?>
    <?php if($this->params->get( 'dokumenty')): ?>
    <td class="center">
      <?php if(!empty($item->file)) { ?>
      <?php echo  jzmluvyHelper::subor_scan($item->id,$item->file,$item->filename,$item->extension,$link,$item->hits,0); }?> 
      <?php if(!empty($item->file2)) { ?>
      <?php echo  jzmluvyHelper::subor_text($item->id,$item->file2,$item->filename2,$item->extension2,$link2,$item->hits2,0); ?>
      <?php } ?> 
    </td><?php endif; ?>
  </tr><?php endif; ?>
<?php endforeach ?>
</tbody>
</table> 
  <input type="hidden" name="option" value="com_jzmluvy" />
  <input type="hidden" name="view" value="objednavky" />
  <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
  <input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
</form>
<?php echo "<!-- jZmluvy ver.".$this->nastavenie->ver." STOP -->"; ?>